package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.recallplayer.RecallPlayerModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_RECALL_PLAYER_TASK_INFO_DETAIL, desc = "客户端请求查看绑定玩家的最新信息与任务")
public class RecallPlayerGetTaskDetailCmd extends AbstractCommand {
    private long recallUserServer;
    private long recallUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RecallPlayerProto.TaskInfoAndUserBaseInfoReqMsg reqMsg = RecallPlayerProto.TaskInfoAndUserBaseInfoReqMsg.parseFrom(packet.getBytes());
        recallUserServer = reqMsg.getRecallUserServer();
        recallUserId = reqMsg.getRecallUserId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(RecallPlayerModule.class).updateAndGetBindReturnUserInfo(recallUserServer, recallUserId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            RecallPlayerProto.TaskInfoAndUserBaseInfoRespMsg.Builder builder = RecallPlayerProto.TaskInfoAndUserBaseInfoRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_RECALL_PLAYER_TASK_INFO_DETAIL, builder);
        }
    }
}
